using System;
using System.IO;
using System.Windows.Forms;

using Tino.Core;
using Tino.Core.Data;

namespace Tino
{
    public class CreateNewDBCommand
    {
        public CreateNewDBCommand() { }

        public bool Create(string path)
        {
            if (File.Exists(path))
                File.Delete(path);
            
            try
            {
                Context.Current.ConnectionString = SqliteConnectionBuilder.GetConnectionString(path);

                // Create all the tables.
                SqliteTablesCreator.CreateTables();

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
        }
    }
}
